import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import New from '@/views/qyxx/new'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [{
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () => import('@/views/redirect')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  {
    path: '/sys',
    component: Layout,
    children: [
      {
        path: 'sysuser',
        component: () => import( '../views/sys/sysuser.vue'),
        hidden: true,
        name: 'sysuser',
        meta: {title: '用戶管理'}
      }, {
        path: 'sysrole',
        component: () => import(/* webpackChunkName: "sysrole" */ '../views/sys/sysrole.vue'),
        hidden: true,
        name: 'sysrole',
        meta: {title: '角色管理'}
      }, {
        path: 'dict',
        component: () => import(/* webpackChunkName: "sysrole" */ '../views/sys/dict.vue'),
        hidden: true,
        name: 'dict',
        meta: {title: '字典管理'}
      }
    ]
  },
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children: [{
      path: 'index',
      component: () => import('@/views/index'),
      name: 'Index',
      meta: {
        title: '首页',
        affix: false
      }
    }]
  },









  {
    path: '/jhrz',
    component: Layout,
    children: [{
        path: 'zbrz',
        component: () => import('@/views/jhrz/zbrz'),
        hidden: true,
        name: 'ZBRZ',
        meta: {
          title: '值班日志管理',
          icon: 'log'
        }
      },

      {
        path: 'dygzp',
        component: () => import('@/views/jhrz/dygzp'),
        hidden: true,
        name: 'DYGZP',
        meta: {
          title: '第一工作票',
          icon: 'log'
        }
      },


    ]
  },







  {
    path: '/ai',
    component: Layout,
    children: [{
      path: 'advisor',
      component: () => import('@/views/maintenancePlan/advisorAssistant'),
      name: 'advisor',
      meta: {
        title: '顾问',
        affix: false
      }
    }]
  },


  {
    path: '/MaintenanceRecord',
    component: Layout,
    children: [{
        path: 'zhongmao',
        component: () => import('@/views/MaintenanceRecord/zhongmao'),
        hidden: true,
        name: 'zhongmao',
        meta: {
          title: '中锚',
          icon: 'svg-name'
        }
      },
      {
        path: 'jueyuanzi',
        component: () => import('@/views/MaintenanceRecord/jueyz'),
        hidden: true,
        name: 'jueyuanzi',
        meta: {
          title: '绝缘子',
          icon: 'svg-name'
        }
      },
      {
        path: 'quanmianjc',
        component: () => import('@/views/MaintenanceRecord/quanmianjc'),
        hidden: true,
        name: 'quanmianjc',
        meta: {
          title: '全面检查',
          icon: 'svg-name'
        }
      },
      {
        path: 'fenxiang',
        component: () => import('@/views/MaintenanceRecord/fenxiang'),
        hidden: true,
        name: 'fenxiang',
        meta: {
          title: '分相',
          icon: 'svg-name'
        }
      },
      {
        path: 'fenduan',
        component: () => import('@/views/MaintenanceRecord/fenduan'),
        hidden: true,
        name: 'fenduan',
        meta: {
          title: '分段',
          icon: 'svg-name'
        }
      },
      {
        path: 'gelikg',
        component: () => import('@/views/MaintenanceRecord/gelikg'),
        hidden: true,
        name: 'gelikg',
        meta: {
          title: '隔离开关',
          icon: 'svg-name'
        }
      },
      {
        path: 'bileiqi',
        component: () => import('@/views/MaintenanceRecord/Bileiqi'),
        hidden: true,
        name: 'bileiqi',
        meta: {
          title: '避雷器',
          icon: 'svg-name'
        }
      },
      {
        path: 'gddianlan',
        component: () => import('@/views/MaintenanceRecord/gddianlan'),
        hidden: true,
        name: 'gddianlan',
        meta: {
          title: '供电电缆',
          icon: 'svg-name'
        }
      },
      {
        path: 'jcwwx',
        component: () => import('@/views/MaintenanceRecord/jcwwx'),
        hidden: true,
        name: 'jcwwx',
        meta: {
          title: '维修记录（杂项）',
          icon: 'svg-name'
        }
      },
      {
        path: 'kuixian',
        component: () => import('@/views/MaintenanceRecord/kuixian'),
        hidden: true,
        name: 'kuixian',
        meta: {
          title: '馈线上网点',
          icon: 'svg-name'
        }
      },
      {
        path: 'maoduan',
        component: () => import('@/views/MaintenanceRecord/MaoDuan'),
        hidden: true,
        name: 'maoduan',
        meta: {
          title: '锚段关节',
          icon: 'svg-name'
        }
      },
      {
        path: 'buchangzz',
        component: () => import('@/views/MaintenanceRecord/buchangzz'),
        hidden: true,
        name: 'buchangzz',
        meta: {
          title: '补偿装置',
          icon: 'svg-name'
        }
      },
      {
        path: 'bczhuyou',
        component: () => import('@/views/MaintenanceRecord/bczhuyou'),
        hidden: true,
        name: 'bczhuyou',
        meta: {
          title: '补偿注油',
          icon: 'svg-name'
        }
      },
      {
        path: 'xiancha',
        component: () => import('@/views/MaintenanceRecord/xiancha'),
        hidden: true,
        name: 'xiancha',
        meta: {
          title: '线岔',
          icon: 'svg-name'
        }
      },
    ]
  },
  {
    path: '/plan',
    component: Layout,
    children: [{
        path: 'task',
        component: () => import('@/views/maintenancePlan/timePlan'),
        hidden: true,
        name: 'Time',
        meta: {
          title: '定时任务计划',
          icon: 'svg-name'
        }
      },
      {
        path: 'assistant',
        component: () => import('@/views/maintenancePlan/assistant'),
        hidden: true,
        name: 'intelligent',
        meta: {
          title: '人工智能助手',
          icon: 'svg-name'
        }
      },
      {
        path: 'trouble',
        component: () => import('@/views/maintenancePlan/troublePlan'),
        hidden: true,
        name: 'Trouble',
        meta: {
          title: '故障任务计划',
          icon: 'svg-name'
        }
      }
    ]
  },
  {
    path: '/base',
    component: Layout,
    children: [{
        path: 'zhanqu',
        component: () => import('@/views/baseData/zhanqu'),
        hidden: true,
        name: 'Zhanqu',
        meta: {
          title: '站区管理',
          icon: 'svg-name'
        }
      },
      {
        path: 'gongqu',
        component: () => import('@/views/baseData/gongqu'),
        hidden: true,
        name: 'Gongqu',
        meta: {
          title: '工区管理',
          icon: 'svg-name'
        }
      },
      {
        path: 'ganhao',
        component: () => import('@/views/baseData/ganhao'),
        hidden: true,
        name: 'Ganhao',
        meta: {
          title: '杆号管理',
          icon: 'svg-name'
        }
      }
    ]
  },
  {
    path: 'gongxu',
    component: () => import('@/views/qyxx/gongxu'),
    hidden: false
  },
  {
    path: 'gongyi',
    component: () => import('@/views/qyxx/gongyi'),
    hidden: false
  },
  {
    path: 'product',
    component: () => import('@/views/qyxx/product'),
    hidden: false
  },
  {
    path: 'gongzz',
    component: () => import('@/views/qyxx/gongzz'),
    hidden: false
  },
  {
    path: 'sjcj',
    component: () => import('@/views/qyxx/sjcj'),
    hidden: false
  },
  {
    path: 'jccx',
    component: () => import('@/views/qyxx/jccx'),
    hidden: false
  },
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [{
    path: '/system/user-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:user:edit'],
    children: [{
      path: 'role/:userId(\\d+)',
      component: () => import('@/views/system/user/authRole'),
      name: 'AuthRole',
      meta: {
        title: '分配角色',
        activeMenu: '/system/user'
      }
    }]
  },
  {
    path: '/system/role-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:role:edit'],
    children: [{
      path: 'user/:roleId(\\d+)',
      component: () => import('@/views/system/role/authUser'),
      name: 'AuthUser',
      meta: {
        title: '分配用户',
        activeMenu: '/system/role'
      }
    }]
  },
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})
